package com.hk.core.authentication.api;


import java.util.Objects;

/**
 * 静态 认证用户信息
 *
 * @author Kevin
 */
public record StaticSecurityContext(UserPrincipal principal) implements SecurityContext {

    @Override
    public <T extends UserPrincipal> T getPrincipalByType(Class<T> type) {
        return type.cast(principal);
    }

    @Override
    public boolean isAuthenticated() {
        return Objects.nonNull(principal)
                && Objects.nonNull(principal.getUserId())
                && Objects.nonNull(principal.getAccount());
    }
}
